# 10. 会议室占用时间段

10 10-1

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', (line) => {
    let str = line.replace(/\[/g, '').replace(/\]/g, '');
    let arr = str.split(',');
    let meetings = [];
    for(let i=0; i<arr.length; i+=2) {
        let start = arr[i];
        let end = arr[i+1];
        meetings.push([start, end]);
    }
    meetings.sort((a, b) => a[0]-b[0]);
    const merged = [meetings[0]];
    for(let i=1; i<meetings.length; i++) {
        const current = merged[merged.length - 1];
        const next = meetings[i];
        if (current[1] >= next[0]) {
            current[1] = Math.max(current[1], next[1]);
        } else {
            merged.push(next);
        }
    }
    console.log(JSON.stringify(merged));
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28